package com.edu.exam.enums.exam;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 题目类型枚举
 * 统一管理各类题目类型定义
 *
 * @author System
 * @version 1.0.0
 */
public enum QuestionType implements BaseEnum {

    // === 客观题类型 ===
    SINGLE_CHOICE("SINGLE_CHOICE", "单选题"),
    MULTIPLE_CHOICE("MULTIPLE_CHOICE", "多选题"),
    TRUE_FALSE("TRUE_FALSE", "判断题"),
    MATCHING("MATCHING", "匹配题"),
    SEQUENCE("SEQUENCE", "排序题"),
    CLASSIFICATION("CLASSIFICATION", "分类题"),

    // === 主观题类型 ===
    FILL_BLANK("FILL_BLANK", "填空题"),
    SHORT_ANSWER("SHORT_ANSWER", "简答题"),
    ESSAY("ESSAY", "论述题"),
    CALCULATION("CALCULATION", "计算题"),

    // === 特殊题型 ===
    PROGRAMMING("PROGRAMMING", "编程题"),
    DRAWING("DRAWING", "作图题"),
    CLOZE("CLOZE", "完形填空"),
    TRANSLATION("TRANSLATION", "翻译题"),
    LISTENING("LISTENING", "听力题"),
    SPEAKING("SPEAKING", "口语题"),

    // === 复合题型 ===
    READING_COMPREHENSION("READING_COMPREHENSION", "阅读理解"),
    CASE_ANALYSIS("CASE_ANALYSIS", "案例分析"),
    EXPERIMENT("EXPERIMENT", "实验题"),

    // === 其他题型 ===
    OTHER("OTHER", "其他");

    private final String code;
    private final String description;

    QuestionType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值，null如果未找到
     */
    public static QuestionType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            return SINGLE_CHOICE;
        }

        for (QuestionType value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return SINGLE_CHOICE;
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值，null如果未找到
     */
    public static QuestionType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return null;
        }

        for (QuestionType value : values()) {
            if (value.getDescription().equals(description)) {
                return value;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}